<template>
  <div style="display: flex;width: 100%;align-items: center">
    <!--          弹性布局                                 居中-->
    <div style="flex:1;">
      <!--                                                          front-size大小    -->
      <span :class="collapseBtnClass" style="cursor: pointer; font-size:18px" @click="collapse"></span>

      <el-breadcrumb spearator="/" style="display:inline-block;margin-left: 10px;">
        <el-breadcrumb-item :to="'/home'">首页</el-breadcrumb-item>
        <el-breadcrumb-item>{{ currentPathName }}</el-breadcrumb-item>
      </el-breadcrumb>
    </div>


    <el-dropdown style="width: 140px; cursor: pointer;float: right">
      <div style="margin: 10px">
        <img :src="user.url" alt=""
             style="width: 36px; border-radius: 50%; position: relative; top: 10px; right:5px">
        <span style="font-size: 15px">{{ user.nickname }}</span><i class="el-icon-arrow-down"
                                                                   style="margin-left: 5px"></i>
      </div>

      <div>                                                               <!--                     增加点击展开 属性-->
        <el-dropdown-menu slot="dropdown" style="margin-right: 25px; width: 120px; text-align: center" trigger="click">
          <el-dropdown-item style="font-size: 14px">
            <router-link to="/person" style="text-decoration: none;color: #6b6767">个人信息</router-link>
          </el-dropdown-item>

          <el-dropdown-item style="font-size: 14px">
            <!--          <router-link to="/" style="text-decoration:none">退出</router-link>-->
            <span style="text-decoration:none" @click="logout">退出</span>
          </el-dropdown-item>
        </el-dropdown-menu>
      </div>
    </el-dropdown>

  </div>

</template>

<script>
import user from "../views/User.vue";

export default {
  name: "Header",
  props: {
    collapseBtnClass: String,
    collapse: Function,//不再报错
  },

  data() {
    return {
      //三目运算符  检测是否有user 进行判断，有该user就将它转化成json，没有该对象则返回空
      user: localStorage.getItem("user") ? JSON.parse(localStorage.getItem("user")) : {}
    }
  },
  methods: {
    logout() {//按退出按钮时返回登录页面
      // this.$router.push("/")
      // localStorage.removeItem("user")//退出时删除前端控制台上面的数据


      //  调用vue/src/store/index.js里的方法，清空缓存
      this.$store.commit("logout")
      this.$message.success("退出成功")
    }
  },


///页面路由获取数据
  computed: {
    currentPathName() {
      return this.$store.state.currentPathName;  //需要监听的数据
    }
  },
  watch: {
    currentPathName(newVal, oldVal) {
      console.log(newVal) //打印
    }
  }
///
}
</script>

<style scoped>

</style>